﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Collections;
using KPIS.Utils;
using KPIS.GERP.GHRMS.BLL;
using KPIS.GERP.GHRMS.IBLL;
using KPIS.GERP.GHRMS.MODEL;
using Telerik.Web.UI;

namespace KPIS.GERP.GHRMS.APP.App_UI.UserControls
{
    public partial class PS_RoyalItems : System.Web.UI.UserControl
    {        
        IRoyalItemBLL royalBLL = new RoyalItemBLL();

        private RadComboBox cmbRoyalItemType;
        private object _dataItem = null;
        protected void Page_Load(object sender, EventArgs e)
        {
            cmbRoyalItemType = (RadComboBox)cbRoyalItemType.FindControl("cbRoyalItemType");

            if (DataItem != null)
            {
                cbRoyalItemType.ListRoyalItemTypeComboBox();

                if (!(DataItem is Telerik.Web.UI.GridInsertionObject))
                {
                    lblRoyalSeq.Text = DataBinder.Eval(DataItem, "Sequence").ToString();
                    cmbRoyalItemType.SelectedValue = Convert.ToString(DataBinder.Eval(DataItem, "RoyalItemTypes.Sequence"));
                    //chkActive.Checked = Convert.ToString(DataBinder.Eval(DataItem, "RecordStatus")) == SystemInfo._ActiveRecordStatus;
                    txtCode.Text = DataBinder.Eval(DataItem, "Code").ToString();
                    txtRoyalName.Text = DataBinder.Eval(DataItem, "Name").ToString();
                    txtRoyalNameShort.Text = DataBinder.Eval(DataItem, "NameShort").ToString();
                }
                btnUpdate.Visible = !(DataItem is Telerik.Web.UI.GridInsertionObject);
                btnAddnew.Visible = (DataItem is Telerik.Web.UI.GridInsertionObject);
            }
        }

        public object DataItem
        {
            get
            {
                return this._dataItem;
            }
            set
            {
                this._dataItem = value;
            }
        }

        protected void btnUpdate_Click(object sender, EventArgs e)
        {
            royalBLL.Update(Int32.Parse(lblRoyalSeq.Text.Trim())
                    , cmbRoyalItemType.SelectedValue
                    , txtCode.Text.Trim()
                    , txtRoyalName.Text.Trim()
                    , txtRoyalNameShort.Text.Trim()
                    //, chkActive.Checked ? SystemInfo._ActiveRecordStatus : SystemInfo._CancelRecordStatus
                    , 1);
        }

        protected void btnCancel_Click(object sender, EventArgs e)
        {

        }

        protected void btnAddnew_Click(object sender, EventArgs e)
        {
            royalBLL.Insert(cmbRoyalItemType.SelectedValue
                    , txtCode.Text.Trim()
                    , txtRoyalName.Text.Trim()
                    , txtRoyalNameShort.Text.Trim()
                //, chkActive.Checked ? SystemInfo._ActiveRecordStatus : SystemInfo._CancelRecordStatus
                    , 1);
        }
    }
}